import constant from 'util/constant.js';
let caches = {
	token: {
		get: function() {
			return localStorage.getItem(constant.cacheskey.jwttoken);
		},
		set: function(token) {
			localStorage.setItem(constant.cacheskey.jwttoken, token);
		},
		remove: function() {
			localStorage.removeItem(constant.cacheskey.jwttoken);
		}
	},
	user: {
		get: function() {
			return sessionStorage.getItem(constant.cacheskey.user) ? JSON.parse(sessionStorage.getItem(constant.cacheskey.user)) :
				null;
		},
		set: function(obj) {
			sessionStorage.setItem(constant.cacheskey.user, JSON.stringify(obj));
		},
		remove: function() {
			sessionStorage.removeItem(constant.cacheskey.user);
		}
	},
	menus: {
		get: function() {
			return sessionStorage.getItem(constant.cacheskey.menus) ? JSON.parse(sessionStorage.getItem(constant.cacheskey.menus)) :
				null;
		},
		set: function(obj) {
			sessionStorage.setItem(constant.cacheskey.menus, JSON.stringify(obj));
		},
		remove: function() {
			sessionStorage.removeItem(constant.cacheskey.menus);
		}
	},
	setting: {
		get: function() {
			return sessionStorage.getItem(constant.cacheskey.systemSetting) ? JSON.parse(sessionStorage.getItem(constant.cacheskey
					.systemSetting)) :
				null;
		},
		set: function(obj) {
			sessionStorage.setItem(constant.cacheskey.systemSetting, JSON.stringify(obj));
		},
		remove: function() {
			sessionStorage.removeItem(constant.cacheskey.systemSetting);
		}
	},
	codes: {
		get: function() {
			return sessionStorage.getItem(constant.cacheskey.codes) ? JSON.parse(sessionStorage.getItem(constant.cacheskey.codes)) :
				null;
		},
		set: function(obj) {
			sessionStorage.setItem(constant.cacheskey.codes, JSON.stringify(obj));
		},
		remove: function() {
			sessionStorage.removeItem(constant.cacheskey.codes);
		}
	},
	roleChildren: {
		get: function() {
			return sessionStorage.getItem(constant.cacheskey.roleChildren) ? JSON.parse(sessionStorage.getItem(constant.cacheskey
					.roleChildren)) :
				null;
		},
		set: function(obj) {
			sessionStorage.setItem(constant.cacheskey.roleChildren, JSON.stringify(obj));
		},
		remove: function() {
			sessionStorage.removeItem(constant.cacheskey.roleChildren);
		}
	},
	departmentChildren: {
		get: function() {
			return sessionStorage.getItem(constant.cacheskey.departmentChildren) ? JSON.parse(sessionStorage.getItem(constant.cacheskey
					.departmentChildren)) :
				null;
		},
		set: function(obj) {
			sessionStorage.setItem(constant.cacheskey.departmentChildren, JSON.stringify(obj));
		},
		remove: function() {
			sessionStorage.removeItem(constant.cacheskey.departmentChildren);
		}
	},
	tabs: {
		get: function() {
			return sessionStorage.getItem(constant.cacheskey.tabs) ? JSON.parse(sessionStorage.getItem(constant.cacheskey.tabs)) :
				null;
		},
		set: function(obj) {
			sessionStorage.setItem(constant.cacheskey.tabs, JSON.stringify(obj));
		},
		remove: function() {
			sessionStorage.removeItem(constant.cacheskey.tabs);
		}
	},
	currentTabId: {
		get: function() {
			return sessionStorage.getItem(constant.cacheskey.currentTabId) ? sessionStorage.getItem(constant.cacheskey
					.currentTabId) :
				null;
		},
		set: function(obj) {
			sessionStorage.setItem(constant.cacheskey.currentTabId, obj);
		},
		remove: function() {
			sessionStorage.removeItem(constant.cacheskey.currentTabId);
		}
	},
	skin: {
		get: function() {
			return sessionStorage.getItem(constant.cacheskey.skin) ? sessionStorage.getItem(constant.cacheskey
					.skin) :
				null;
		},
		set: function(obj) {
			sessionStorage.setItem(constant.cacheskey.skin, obj);
		},
		remove: function() {
			sessionStorage.removeItem(constant.cacheskey.skin);
		}
	},
	cleanCaches: function() {
		caches.user.remove();
		caches.menus.remove();
		caches.codes.remove();
		caches.roleChildren.remove();
		caches.departmentChildren.remove();
		caches.tabs.remove();
		caches.setting.remove();
		caches.currentTabId.remove();
		caches.skin.remove();
	},
	cleanAll: function() {
		caches.user.remove();
		caches.menus.remove();
		caches.codes.remove();
		caches.roleChildren.remove();
		caches.departmentChildren.remove();
		caches.tabs.remove();
		caches.setting.remove();
		caches.currentTabId.remove();
		caches.skin.remove();
		caches.token.remove();
	}
}

export default caches;
